package com.tfjybj.itoo.teach.provider.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.dmsdbj.itoo.tool.base.entity.YearSemesterEntity;
import com.dmsdbj.itoo.tool.base.service.impl.BaseServicePlusImpl;
import com.dmsdbj.itoo.tool.business.ItooResult;
import com.dmsdbj.itoo.tool.constantutil.YearSemester;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.teach.entity.AcademyEntity;
import com.tfjybj.itoo.teach.entity.ElectiveCoursePubEntity;
import com.tfjybj.itoo.teach.model.CourseModel;
import com.tfjybj.itoo.teach.model.ElectiveCoursePubModel;
import com.tfjybj.itoo.teach.provider.dao.ElectiveCoursePubDao;
import com.tfjybj.itoo.teach.provider.service.AcademyService;
import com.tfjybj.itoo.teach.provider.service.CourseService;
import com.tfjybj.itoo.teach.provider.service.ElectiveCoursePubService;
import com.tfjybj.itoo.teach.template.ElectiveCoursePubExportTemplate;
import com.tfjybj.itoo.teach.template.ElectiveCoursePubTemplate;
import lombok.extern.slf4j.Slf4j;
import org.jplus.hyberbin.excel.utils.ExcelUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.util.*;

import static com.tfjybj.itoo.teach.provider.until.DemoConstants.*;

/**
 * ElectiveCoursePubService接口实现类
 * ${base}表
 *
 * @author 田成荣
 * @version 2.0.0
 * @since 2.0.0 2018-11-08 19:34:10
 */
@Service("electiveCoursePubService")
@Slf4j
public class ElectiveCoursePubServiceImpl extends BaseServicePlusImpl<ElectiveCoursePubDao, ElectiveCoursePubEntity> implements ElectiveCoursePubService {

    //region 模板生成
    @Resource
    private ElectiveCoursePubDao electiveCoursePubDao;

    @Resource
    private CourseService courseService;

    @Resource
    private AcademyService academyService;

    @Resource
    private RedisTemplate<String, ElectiveCoursePubTemplate> redisTemplate;

    //下载导入EXCEL模板需要的列
    private static final String[] DOWNLOAD_IMPORT_COLUMNS = new String[]{"semesterName", "academy", "courseName", "courseCode", "theoryClassHour", "practiceClassHour", "examinationForm", "applyer"};

    //导出EXCEL模板需要的列
    private static final String[] EXPORT_COLUMNS = new String[]{"semesterName", "courseCode", "courseName", "courseCategoryName", "courseNatureName", "theoryClassHour", "practiceClassHour", "classHour", "examinationForm"};

    @Override
    public PageInfo<ElectiveCoursePubEntity> queryByLikeCourseId(String courseId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(electiveCoursePubDao.queryLikeCourseId(courseId));
    }
    //endregion

    /* **********************************以下为非模板生成的内容********************************* */

    /**
     * 根据课程ID和学年ID查询公选课培养计划
     *
     * @param courseId   课程ID
     * @param semesterId 学年ID
     * @return 公选课培养计划实体集合
     * @author 李建帅
     * @since 2.0.0 2018/11/14 15:39
     */
    @Override
    public List<ElectiveCoursePubModel> queryByCoSeId(String courseId, String semesterId) {
        return electiveCoursePubDao.queryByCoSeId(courseId, semesterId);
    }

    /**
     * 根据学年学期ID分页查询公选课培养计划
     *
     * @param semesterId 学年学期ID
     * @param pageNo     页码
     * @param pageSize   每页条数
     * @return 公选课培养计划实体集合
     * @author 李建帅
     * @since 2.0.0 2018-11-15 10:39:08
     */
    @Override
    public PageInfo<ElectiveCoursePubModel> queryAllBySemesterId(String semesterId, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        return new PageInfo<>(electiveCoursePubDao.queryAllBySemesterId(semesterId));
    }

    /**
     * 默认分页查询所有的公选课培养计划
     *
     * @param pageSize 每页条数
     * @return 公选课培养计划实体集合
     * @pageNo 页码
     * @author 李建帅
     * @since 2.0.0 2018-11-15 11:25:36
     */
    @Override
    public PageInfo<ElectiveCoursePubModel> queryAllEcpPlan(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        return new PageInfo<>(importValue(electiveCoursePubDao.queryAllEcpPlan()));
    }

    /**
     * 根据公选课培养计划ID查询公选课培养计划详情
     *
     * @param idList 公选课培养计划ID
     * @return 公选课培养计划实体集合
     * @author 李建帅
     * @since 2.0.0 2018/11/15 19:11
     */
    @Override
    public List<ElectiveCoursePubModel> queryEcpPlanById(List<String> idList) {
        return importValue(electiveCoursePubDao.queryEcpPlanById(idList));
    }

    /**
     * 查询所有的学年学期
     *
     * @return 学年学期实体集合
     * @author 李建帅
     * @since 2.0.0 2018/11/15 21:18
     */
    @Override
    public List<YearSemesterEntity> querySemester() {
        return YearSemester.getYearSemesterList(-2, 6);
    }

    /**
     * 根据学年学期ID查询公选课课程ID集合
     *
     * @param semesterId 学年学期Id
     * @return 公选课课程ID集合
     * @author 李建帅
     * @since 2.0.0 2018/11/18 8:22
     */
    @Override
    public List<String> queryCourseIdBySemesterId(String semesterId) {
        return electiveCoursePubDao.queryCourseIdBySemesterId(semesterId);
    }

    /**
     * 根据课程名称模糊查询公选课培养计划
     *
     * @param strLike 模糊查询条件（课程名称）
     * @return 公选课培养计划实体集合
     * @author 李建帅
     * @since 2.0.0 2018/11/19 9:15
     */
    @Override
    public PageInfo<ElectiveCoursePubModel> queryByStrLike(Integer pageNo, Integer pageSize, String strLike) {
        PageHelper.startPage(pageNo, pageSize);
        return new PageInfo<>(importValue(electiveCoursePubDao.queryByStrLike(strLike.trim())));
    }

    /**
     * 根据条件查询公选课培养计划
     *
     * @param semesterId 学期ID
     * @param academyId  学院Id
     * @return 公选课培养计划实体集合
     * @author 李建帅
     * @since 2.0.0 2018-11-19 10:28:18
     */
    @Override
    public PageInfo<ElectiveCoursePubModel> queryBySemAcaId(String semesterId, String academyId, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        return new PageInfo<>(importValue(electiveCoursePubDao.queryBySemAcaId(semesterId, academyId)));
    }

    /**
     * 将培养计划中的名称字段转换为ID并填充到实体中去
     *
     * @param electiveCoursePubModelList 培养计划实体集合
     * @return 填充好数据的培养计划实体集合
     * @author 李建帅
     * @since 2.0.0 2018/11/17 14:21
     */
    private List<ElectiveCoursePubModel> importValue(List<ElectiveCoursePubModel> electiveCoursePubModelList) {
        if (CollectionUtils.isEmpty(electiveCoursePubModelList)) {
            return electiveCoursePubModelList;
        }

        //将类型ID转换成具体的名称

        //课程类别（1-理论课、2-实践课、3-理论实践课）；
        Map<String, String> courseCategoryMap = new HashMap<>();
        courseCategoryMap.put("1", "理论课");
        courseCategoryMap.put("2", "实践课");
        courseCategoryMap.put("3", "理论实践课");

        //考核形式（1-考查、2-考试）
        Map<String, String> examinationFormMap = new HashMap<>();
        examinationFormMap.put("1", "考查");
        examinationFormMap.put("2", "考试");

        Map<String, String> courseNatureMap = new HashMap<>();
        courseNatureMap.put("1", "人文社科");
        courseNatureMap.put("2", "艺术体育");
        courseNatureMap.put("3", "自然科学");

        //填充数据
        for (int i = 0; i < electiveCoursePubModelList.size(); i++) {

            //补充学年学期名称
            if (!StringUtils.isEmpty(electiveCoursePubModelList.get(i).getSemesterId())) {
                electiveCoursePubModelList.get(i).setSemesterName(YearSemester.getYearSemesterNameByCode(electiveCoursePubModelList.get(i).getSemesterId()));
            }

            //填充课程类别
            if (!StringUtils.isEmpty(electiveCoursePubModelList.get(i).getCourseCategory())) {
                String courseCategoryId = electiveCoursePubModelList.get(i).getCourseCategory();
                electiveCoursePubModelList.get(i).setCourseCategoryName(courseCategoryMap.get(courseCategoryId));
            }

            //填充考核形式
            if (!StringUtils.isEmpty(electiveCoursePubModelList.get(i).getExaminationFormId())) {
                String examinationFormId = electiveCoursePubModelList.get(i).getExaminationFormId();
                electiveCoursePubModelList.get(i).setExaminationForm(examinationFormMap.get(examinationFormId));
            }

            //填充课程性质
            if (!StringUtils.isEmpty(electiveCoursePubModelList.get(i).getCourseNature())) {
                String courseNature = electiveCoursePubModelList.get(i).getCourseNature();
                electiveCoursePubModelList.get(i).setCourseNatureName(courseNatureMap.get(courseNature));
            }
        }
        return electiveCoursePubModelList;
    }

    /**
     * 下载培养计划模板，批量导入使用
     *
     * @param response 响应
     * @return 下载模板是否成功
     * @author 李建帅
     * @since 2.0.0 2018-11-15 08:53:53
     */
    @Override
    public boolean downLoadTemplate(HttpServletResponse response) {
        Map<Serializable, Serializable> map = new HashMap<>(16);
        List<ElectiveCoursePubTemplate> templateList = new ArrayList<>();
        ElectiveCoursePubTemplate electiveCoursePubTemplate = new ElectiveCoursePubTemplate();

        //添加下载模板范例
        electiveCoursePubTemplate.setSemesterName("2017-2018学年第二学期");
        electiveCoursePubTemplate.setAcademy("数学与信息科学学院");
        electiveCoursePubTemplate.setCourseName("随机应用");
        electiveCoursePubTemplate.setCourseCode("041100002");
        electiveCoursePubTemplate.setTheoryClassHour("10");
        electiveCoursePubTemplate.setPracticeClassHour("10");
        electiveCoursePubTemplate.setExaminationForm("考查");
        electiveCoursePubTemplate.setApplyer("李四");
        templateList.add(electiveCoursePubTemplate);

        //sheet的名字
        map.put(SHEET_NAME, "公选课培养计划");
        //需要导入的字段
        map.put(COLUMNS, DOWNLOAD_IMPORT_COLUMNS);
        //表格的标题
        map.put(TITLE, "公选课培养计划");
        map.put(NAME, "公选课培养计划模板");
        map.put(DATA_LIST, (Serializable) templateList);
        try {
            ExcelUtil.exportExcel(map, response);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * 批量导入
     *
     * @param
     * @return
     * @author 李建帅
     * @since 2.0.0 2018/11/15 14:29
     */
    @Override
    public ItooResult importTemplate(MultipartFile multipartFile, HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("UTF-8");

        try {
            //校验文件是否存在
            String fileName = multipartFile.getOriginalFilename();
            if (fileName == null) {
                log.error("导入失败,fileName is null!");
                return ItooResult.build(ItooResult.FAIL, "传入的文件为空！");
            }

            //EXCEL解析成List
            Map<Serializable, Serializable> map = new HashMap<>(4);
            map.put(SHEET_NAME, "公选课培养计划");
            map.put(CLASS, ElectiveCoursePubTemplate.class);
            List<ElectiveCoursePubTemplate> electiveCoursePubTemplateList = ExcelUtil.importExcel(Objects.requireNonNull(fileName), map, request, response);

            if (CollectionUtils.isEmpty(electiveCoursePubTemplateList)) {
                return ItooResult.build(ItooResult.FAIL, "导入的数据为空，请填写！");
            }
            //定义导入的错误数据集合并存redis中形式的<String,ElectiveCoursePubTemplate>
            List<ElectiveCoursePubTemplate> errorTPTList = new ArrayList<>();
            String errorTPTListId = IdWorker.getIdStr();
            Long size = redisTemplate.opsForZSet().size(errorTPTListId);
            size = size == null ? 0L : size;

            for (ElectiveCoursePubTemplate excelTPT : electiveCoursePubTemplateList) {

                if (!this.verify(excelTPT)) {
                    ElectiveCoursePubTemplate ecpTemplate = new ElectiveCoursePubTemplate();
                    BeanUtils.copyProperties(excelTPT, ecpTemplate);

                    errorTPTList.add(ecpTemplate);
                    redisTemplate.opsForZSet().add(errorTPTListId, ecpTemplate, size + 1);
                    continue;
                }

                //插入对应的值
                ElectiveCoursePubEntity electiveCoursePubEntity = insertValue(excelTPT);

                this.save(electiveCoursePubEntity);
            }
            //不符合条件的信息返回
            if (!CollectionUtils.isEmpty(errorTPTList)) {
                return ItooResult.build("0001", "部分导入失败", errorTPTListId);
            }
        } catch (Exception e) {
            return ItooResult.build(ItooResult.FAIL, "导入数据异常！", e);
        }
        return ItooResult.build(ItooResult.FAIL, "导入数据成功！");
    }

    /**
     * 根据考核形式名称获得ID
     *
     * @param examinationForm 考核形式名称
     * @return 考核形式ID
     * @author 李建帅
     * @since 2.0.0 2018/11/17 15:06
     */
    private String getIdByExaminationForm(String examinationForm) {
        Map<String, String> examinationFormMap = new HashMap<>();
        examinationFormMap.put("考查", "1");
        examinationFormMap.put("考试", "2");

        return examinationFormMap.get(examinationForm);
    }

    /**
     * 将导入模板的值赋值给实体
     *
     * @param electiveCoursePubTemplate 公选课培养计划导入模板
     * @return ElectiveCoursePubEntity 公选课培养计划实体
     * @author 李建帅
     * @since 2.0.0 2018/12/2 15:01
    */
    private ElectiveCoursePubEntity insertValue(ElectiveCoursePubTemplate electiveCoursePubTemplate){

        ElectiveCoursePubEntity electiveCoursePubEntity = new ElectiveCoursePubEntity();
        //将导入内容放到entity中对应的属性中去
        BeanUtils.copyProperties(electiveCoursePubTemplate, electiveCoursePubEntity);

        //培养计划ID
        electiveCoursePubEntity.setId(IdWorker.getIdStr());
        //可用
        electiveCoursePubEntity.setIsUse(1);
        //未排课
        electiveCoursePubEntity.setIsArrangement(0);

        //考核形式-需要转化成ID
        electiveCoursePubEntity.setExaminationFormId(getIdByExaminationForm(electiveCoursePubTemplate.getExaminationForm().trim()));

        //选填数据
        //操作者
        electiveCoursePubEntity.setOperator("批量导入");
        //备注
        electiveCoursePubEntity.setRemark("开发测试数据");

        return electiveCoursePubEntity;
    }

    /**
     * 判断导入的信息是否为空
     *
     * @param excelTPT 需要导入的信息
     * @return boolean 导入的字段是否为空
     * @author 李建帅
     * @since 2.0.0 2018/11/16 20:43
     */
    private boolean verify(ElectiveCoursePubTemplate excelTPT) {
        if (StringUtils.isEmpty(excelTPT.getCourseCode())) {
            excelTPT.setFailReason("课程代码未填写");
            log.warn("导入失败,课程代码未填写,excelFooEntity-{}", excelTPT);
            return false;
        }
        if (StringUtils.isEmpty(excelTPT.getCourseName())) {
            excelTPT.setFailReason("课程名称未填写");
            log.warn("导入失败,课程名称未填写,excelFooEntity-{}", excelTPT);
            return false;
        }
        if (StringUtils.isEmpty(excelTPT.getSemesterName())) {
            excelTPT.setFailReason("学年学期未填写");
            log.warn("导入失败,学年学期未填写,excelFooEntity-{}", excelTPT);
            return false;
        }

        //获取学院的ID
        PageInfo<AcademyEntity> academyEntityPageInfo = academyService.queryByLikeName(excelTPT.getAcademy().trim(), 1, 1);
        if (CollectionUtils.isEmpty(academyEntityPageInfo.getList())) {
            excelTPT.setFailReason(excelTPT.getAcademy() + "该学院名称不存在！");
            log.warn(excelTPT.getAcademy() + "该学院名称不存在！-", excelTPT);
            return false;
        }

        //通过课程ID查询课程的信息
        List<CourseModel> courseModel = courseService.isExistByCode(excelTPT.getCourseCode());
        if (CollectionUtils.isEmpty(courseModel)) {
            excelTPT.setFailReason("找不到课程代码为:" + excelTPT.getCourseCode() + "的课程");
            log.warn("找不到课程代码为:" + excelTPT.getCourseCode() + "的课程");
            return false;
        }

        //判断查询出的课程名称与导入时写入的课程名称是否相同
        if (!courseModel.get(0).getName().equals(excelTPT.getCourseName().trim())) {
            excelTPT.setFailReason("课程代码：" + excelTPT.getCourseCode() + "所对应的课程名称与输入的课程名称：" + excelTPT.getCourseName() + "不匹配");
            log.warn("课程代码：" + excelTPT.getCourseCode() + "所对应的课程名称与输入的课程名称：" + excelTPT.getCourseName() + "不匹配-", excelTPT);
            return false;
        }

        //判断课程类型时候是否为公选课类型，为公选课之外的课程类型则返回错误信息，不导入
        if (!StringUtils.isEmpty(courseModel.get(0).getCourseType())) {
         if (!courseModel.get(0).getCourseType().equals("4")){
            excelTPT.setFailReason("不支持导入公共选修课之外的课程类型");
            log.warn("不支持导入公共选修课之外的课程类型-",excelTPT);
            return false;
         }
        }

        //课程ID
        excelTPT.setCourseId(courseModel.get(0).getId());
        //学年学期ID（根据学期名称查询获得）
        excelTPT.setSemesterId(YearSemester.getYearSemesterCodeByName(excelTPT.getSemesterName().trim()));

        //判断培养计划是否已经存在
        String idIsExist = electiveCoursePubDao.findIdIsExist(excelTPT.getSemesterId(), excelTPT.getCourseId());
        if (!StringUtils.isEmpty(idIsExist)) {
            excelTPT.setFailReason("该学期：" + excelTPT.getSemesterName() + "的课程：" + excelTPT.getCourseName() + "已存在对应的培养计划，不能重复添加");
            log.warn("该学期：" + excelTPT.getSemesterName() + "的课程：" + excelTPT.getCourseName() + "已存在对应的培养计划，不能重复添加-", excelTPT);
            return false;
        }
        return true;
    }

    /**
     * 根据学年ID和课程id判断该培养计划是否已经存在
     *
     * @param semesterId 学年Id
     * @param courseId   课程Id
     * @return boolean 存在true/不存在false
     * @author 李建帅
     * @since 2.0.0 2018/11/24 15:29
     */
    @Override
    public Boolean findIdIsExist(String semesterId, String courseId) {
        String idIsExist = electiveCoursePubDao.findIdIsExist(semesterId, courseId);
        if (StringUtils.isEmpty(idIsExist)) {
            return false;
        }
        return true;
    }

    /**
     * 根据培养计划ID导出培养计划
     *
     * @param response response
     * @param idList   培养计划Id
     * @return 导出的结果
     * @author 李建帅
     * @since 2.0.0 2018-11-18 09:09:23
     */
    @Override
    public ItooResult exportByTpId(HttpServletResponse response, List<String> idList) {
        Map<Serializable, Serializable> map = new HashMap<>(16);

        map.put(SHEET_NAME, "公选课培养计划");
        //要导出的字段
        map.put(COLUMNS, EXPORT_COLUMNS);
        //导出表格的标题
        map.put(TITLE, "公选课培养计划信息");
        map.put(NAME, "公选课培养计划信息表");
        //要导出的数据
        List<ElectiveCoursePubExportTemplate> electiveCoursePubExportTemplateList = new ArrayList<>();

        List<ElectiveCoursePubModel> electiveCoursePubModelList = importValue(electiveCoursePubDao.queryEcpPlanById(idList));
        for (ElectiveCoursePubModel electiveCoursePubModel : electiveCoursePubModelList) {
            ElectiveCoursePubExportTemplate electiveCoursePubExportTemplate = new ElectiveCoursePubExportTemplate();
            BeanUtils.copyProperties(electiveCoursePubModel, electiveCoursePubExportTemplate);

            electiveCoursePubExportTemplateList.add(electiveCoursePubExportTemplate);
        }
        //为空不进行导出
        if (CollectionUtils.isEmpty(electiveCoursePubExportTemplateList)) {
            return ItooResult.build(ItooResult.FAIL, "没有要导出的数据！");
        }
        map.put(DATA_LIST, (Serializable) electiveCoursePubExportTemplateList);

        //导出
        try {
            ExcelUtil.exportExcel(map, response);
        } catch (Exception e) {
            log.error("导出失败,未知的异常--" + e);
            return ItooResult.build(ItooResult.FAIL, "导出信息失败！", e);
        }
        return ItooResult.build(ItooResult.SUCCESS, "导出信息成功！");
    }

    /**
     * 根据条件导出培养计划
     *
     * @param response   响应
     * @param academyId  学院Id
     * @param semesterId 学期ID
     * @param strLike    模糊条件
     * @return 导出结果信息
     * @author 李建帅
     * @since 2.0.0 2018-11-25 11:34:25
     */
    @Override
    public ItooResult exportByStrLike(HttpServletResponse response, String academyId, String semesterId, String strLike) {
        Map<Serializable, Serializable> map = new HashMap<>(16);

        map.put(SHEET_NAME, "公选课培养计划");
        //要导出的字段
        map.put(COLUMNS, EXPORT_COLUMNS);
        //导出表格的标题
        map.put(TITLE, "公选课培养计划信息");
        map.put(NAME, "公选课培养计划信息表");
        //要导出的数据
        List<ElectiveCoursePubExportTemplate> electiveCoursePubExportTemplateList = new ArrayList<>();

        List<ElectiveCoursePubModel> electiveCoursePubModelList = importValue(electiveCoursePubDao.exportByStrLike(academyId, semesterId, strLike));
        for (ElectiveCoursePubModel electiveCoursePubModel : electiveCoursePubModelList) {
            ElectiveCoursePubExportTemplate electiveCoursePubExportTemplate = new ElectiveCoursePubExportTemplate();
            BeanUtils.copyProperties(electiveCoursePubModel, electiveCoursePubExportTemplate);

            electiveCoursePubExportTemplateList.add(electiveCoursePubExportTemplate);
        }
        //为空不进行导出
        if (CollectionUtils.isEmpty(electiveCoursePubExportTemplateList)) {
            return ItooResult.build(ItooResult.FAIL, "没有要导出的数据！");
        }
        map.put(DATA_LIST, (Serializable) electiveCoursePubExportTemplateList);

        //导出
        try {
            ExcelUtil.exportExcel(map, response);
        } catch (Exception e) {
            log.error("导出失败,未知的异常--" + e);
            return ItooResult.build(ItooResult.FAIL, "导出信息失败！", e);
        }
        return ItooResult.build(ItooResult.SUCCESS, "导出信息成功！");
    }

    /**
     * 导出错误数据
     *
     * @param response 响应
     * @param errorListId 为成功导入的分组id
     * @return 课程信息model
     * @author 李建帅
     * @since 2018-12-2 08:11:58
     */
    @Override
    public boolean downErrorList(String errorListId, HttpServletResponse response) {
        // redis 取出没有成功导入的培养计划信息
        Set set = redisTemplate.opsForZSet().range(errorListId, 0, -1);
        List<ElectiveCoursePubTemplate> electiveCoursePubTemplateList = new ArrayList<>(set);
        // 清空redis数据
        redisTemplate.delete(errorListId);

        //导出
        if (CollectionUtils.isEmpty(electiveCoursePubTemplateList)) {
            return false;
        }

        Map<Serializable, Serializable> errorMap = new HashMap<>(16);
        errorMap.put(NAME, "未导入的公选课培养计划信息");
        errorMap.put(SHEET_NAME, "公选课培养计划");
        errorMap.put(TITLE, "未导入的信息");
        errorMap.put(COLUMNS, new String[]{"semesterName", "academy", "courseName", "courseCode", "theoryClassHour", "practiceClassHour", "examinationForm", "applyer","failReason"});
        errorMap.put(DATA_LIST, (Serializable) electiveCoursePubTemplateList);
        try {
            ExcelUtil.exportExcel(errorMap, response);
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}
